package com.bawei.router.degrade

import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.callback.NavigationCallback
import com.bawei.base.RoutePath

/**
 * Author: Jason Zhang
 * Date: 2024/12/16
 * Desc: 局部降级策略
 */
class LocalDegradeService constructor(private val group: String = "", private val path:String = ""): NavigationCallback {

    //默认组和路径
    private var defaultGroup: String = RoutePath.GROUP_EMPTY
    private var defaultPath: String = RoutePath.PATH_EMPTY_PAGE

    /**
     * 页面找到的回调方法
     */
    override fun onFound(postcard: Postcard?) {

    }

    /**
     * 页面没有找到
     */
    override fun onLost(postcard: Postcard) {
        if (!group.isNullOrEmpty()){
            defaultGroup = group
        }

        if (!path.isNullOrEmpty()){
            defaultPath = path
        }

        //重置路由参数
        postcard.group = defaultGroup
        postcard.path = defaultPath

        //页面跳转
        postcard.navigation()

    }

    /**
     * 页面跳转成功
     */
    override fun onArrival(postcard: Postcard?) {

    }

    /**
     * 页面跳转拦截
     */
    override fun onInterrupt(postcard: Postcard?) {

    }


}